﻿<UserControl x:Class="RWG.Silverlight.SPDiscussion.MainPage"
               xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
     xmlns:common="clr-namespace:System.Windows;assembly=System.Windows.Controls" 
    
    xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"

    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
    <UserControl.Resources>
       <common:HierarchicalDataTemplate x:Key="ChildTemplate" >
        <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Author.PersonName}"  />
                <TextBlock Text="{Binding DiscussionLastUpdated}"  />
            </StackPanel>
        </common:HierarchicalDataTemplate>
        <common:HierarchicalDataTemplate x:Key="NameTemplate" 
        ItemsSource="{Binding Path=ChildMessages}" 
        ItemTemplate="{StaticResource ChildTemplate}">
          
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Author.PersonName}"  />
                <TextBlock Text="{Binding DiscussionLastUpdated}"  />
            </StackPanel>
        </common:HierarchicalDataTemplate>
    </UserControl.Resources>
    <Canvas x:Name="LayoutRoot" >
        <StackPanel>
            <TextBlock Text="{Binding ListID}" />

            <data:DataGrid x:Name="dgDiscussions"  
                           AutoGenerateColumns="False"
                           SelectionChanged="dgDiscussions_SelectionChanged"   
                           ItemsSource="{Binding Discussions}">
                <data:DataGrid.RowDetailsTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Vertical">
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding Author.PersonName}"  />
                                <TextBlock Text="{Binding DiscussionLastUpdated}"  />
                            </StackPanel>
                            <controls:TreeView Width="400"  Height="300" ItemsSource="{Binding Messages}" 
    ItemTemplate="{StaticResource NameTemplate}" x:Name="myTreeView" SelectedItemChanged="myTreeView_SelectedItemChanged" />

                        </StackPanel>
                    </DataTemplate>
                </data:DataGrid.RowDetailsTemplate>
                <data:DataGrid.Columns>
                    <data:DataGridTemplateColumn>
                        <data:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Image Source="ARROW3A.PNG" />
                            </DataTemplate>
                        </data:DataGridTemplateColumn.CellTemplate>
                            
                        
                    </data:DataGridTemplateColumn>
                    <data:DataGridTextColumn Binding="{Binding Title}" Header="Title"  />
                </data:DataGrid.Columns>
            </data:DataGrid>
                  </StackPanel>
    </Canvas>
</UserControl>